package com.sylar.happygps;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

public class WebActivity extends Activity implements OnClickListener {

	private WebView my_web;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.web);

		Button btn_title_left = (Button) findViewById(R.id.btn_title_left);
		btn_title_left.setVisibility(View.VISIBLE);
		btn_title_left.setText(R.string.app_name);
		btn_title_left.setOnClickListener(this);

		Button btn_title_right = (Button) findViewById(R.id.btn_title_right);
		btn_title_right.setVisibility(View.VISIBLE);
		btn_title_right.setText("返回");
		btn_title_right.setOnClickListener(this);

		TextView tv_title_name = (TextView) findViewById(R.id.tv_title_name);
		tv_title_name.setVisibility(View.GONE);

		my_web = (WebView) findViewById(R.id.my_web);
		my_web.getSettings().setJavaScriptEnabled(true);
		my_web.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		String url = this.getIntent().getStringExtra("openurl");

		if (!TextUtils.isEmpty(url)) {
			my_web.loadUrl(url);
		} else {
			my_web.loadUrl("http://www.baidu.com");
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_left:
			finish();
			break;
		case R.id.btn_title_right:
			if (my_web != null)
				my_web.goBack();
			break;
		default:
			break;
		}
	}
}
